#include"Respone.h"
#include"MemoryPool.h"

using namespace Http;
const std::string Respone::Context_Type = "Content-Type";

Respone::Respone() {
    body_size = 0;
    init();
}
Respone::~Respone() {
    if (body)
        wjc::MemoryPool::getLocalInstance()->freeMemory(body);
}
void Respone::init() {
    kv.clear();
    body = nullptr;
    b_idx = 0;
    next_chain = "";
    view = "";
    location = "";
}

void Respone::appendBody(const char* data, size_t size) {
    if (size>0&&(body == nullptr || (body_size - b_idx) < size)) {
        body_size = b_idx + size;
        char* tmp = static_cast<char*>(wjc::MemoryPool::getLocalInstance()->getMemory(body_size));
        if (body) {
            memcpy(tmp, body, b_idx);
            wjc::MemoryPool::getLocalInstance()->freeMemory(body);
        }
        body = tmp;
    }
    memcpy(body + b_idx, data, size);
    b_idx += size;
}